// pages/detail/detail.js

let action = '';
let moveY = 200;
let animation = animation = wx.createAnimation({
  transformOrigin: "50% 50%",
  duration: 400,
  timingFunction: "ease",
  delay: 0
});
animation.translateY(moveY + 'vh').step();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    backgroundVisible: false,
    animation: animation,
    bg: 'background',
    swiperData: [{
        src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/4c33eb4b0d0851bd124a27082690bbe6.jpg"
      },
      {
        src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/4c33eb4b0d0851bd124a27082690bbe6.jpg"
      },
    ],
    eName: "Teatime", //英文名
    zhName: "浅草", // 中文名
    price: "298.00", // 价格
    detailsLabelData: [{
        label: "新品"
      },
      {
        label: "人气"
      }
    ], // 标签
    detailsTasteData: [{
        src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/micon-27.png",
        name: "绿茶"
      },
      {
        src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/micon-27.png",
        name: "绿茶"
      }
    ], // 材料标签
    weight: "908", // 重量
    lb: "2.0", // 磅
    detailsOptionsData: [{
        src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/size.png",
        info: "18x18cm"
      },
      {
        src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/laid.png",
        info: "含10套餐具（蜡烛需单独订购）"
      },
      {
        src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/unmber.png",
        info: "适合7-8人分享"
      },
      {
        src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/time.png",
        info: "最早明天 09:30配送"
      }
    ], // 尺寸，餐具，人数，配送时间
    fresh: "0－4℃保藏10小时，5℃食用为佳", // 保鲜条件
    sweet: 3, //甜度
    introduction: '/“浅草才能没马蹄”/ \n /切着吃的雨前西湖龙井/ \n /中国绿茶与爽脆果实，工笔勾勒一杯好茶/ \n /复杂而纯粹的深浅绿意/ \n * 本款为季节性产品，夹心层5月10日起为梨。', //描述
    detailsImgData: [{
        src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/8697fe7846058940e56725827af1f290.jpg"
      },
      {
        src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/5a10b57019cb997308d8329a8b3e1f66.jpg"
      },
    ],
    recommendListData: [{
        src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/58c4227141bbcf6efe30b5940267a1a9.jpg",
        name: "米道",
        price: "298.00",
        lb: "1.0",
        weight: "454"
      },
      {
        src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/58c4227141bbcf6efe30b5940267a1a9.jpg",
        name: "米道",
        price: "298.00",
        lb: "1.0",
        weight: "454"
      },
      {
        src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/58c4227141bbcf6efe30b5940267a1a9.jpg",
        name: "米道",
        price: "298.00",
        lb: "1.0",
        weight: "454"
      },
      {
        src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/58c4227141bbcf6efe30b5940267a1a9.jpg",
        name: "米道",
        price: "298.00",
        lb: "1.0",
        weight: "454"
      },
    ], // 推荐商品
    typeDetailData: {
      "productsArr": [{
        "productsArr": [{
            "id": "227",
            "size": "13x13cm",
            "suite_amount": "\u9002\u54083-4\u4eba\u5206\u4eab",
            "booking_hour_limited": "5",
            "cutlery_content": "\u542b5\u5957\u9910\u5177\uff08\u8721\u70db\u9700\u5355\u72ec\u8ba2\u8d2d\uff09",
            "price": "268.00",
            "mktprice": "268.00",
            "spec": "1.0\u78c5",
            "pound": "1.00",
            "has_spec_img": 1,
            "img_url": "\/themes\/wap\/img\/1.00P-full-13.00.jpg",
            "is_default": "true",
            "has_stock": 9998,
            "cat_id": "3",
            "bn": "201408-10",
            "enName": "Black Forest ",
            "simpleName": "\u9ed1\u68ee\u6797",
            "cakeGoodsId": "8",
            "weight": 454
          },
          {
            "id": "239",
            "size": "17x17cm",
            "suite_amount": "\u9002\u54087-8\u4eba\u5206\u4eab",
            "booking_hour_limited": "5",
            "cutlery_content": "\u542b10\u5957\u9910\u5177\uff08\u8721\u70db\u9700\u5355\u72ec\u8ba2\u8d2d\uff09",
            "price": "398.00",
            "mktprice": "398.00",
            "spec": "2.0\u78c5",
            "pound": "2.00",
            "has_spec_img": 1,
            "img_url": "\/themes\/wap\/img\/2.00P-full-17.00.jpg",
            "is_default": "false",
            "has_stock": 9998,
            "cat_id": "3",
            "bn": "201408-20",
            "enName": "Black Forest ",
            "simpleName": "\u9ed1\u68ee\u6797",
            "cakeGoodsId": "8",
            "weight": 908
          },
          {
            "id": "245",
            "size": "23x23cm",
            "suite_amount": "\u9002\u540811-12\u4eba\u5206\u4eab",
            "booking_hour_limited": "5",
            "cutlery_content": "\u542b15\u5957\u9910\u5177\uff08\u8721\u70db\u9700\u5355\u72ec\u8ba2\u8d2d\uff09",
            "price": "598.00",
            "mktprice": "598.00",
            "spec": "3.0\u78c5",
            "pound": "3.00",
            "has_spec_img": 1,
            "img_url": "\/themes\/wap\/img\/3.00P-full-23.00.jpg",
            "is_default": "false",
            "has_stock": 9999,
            "cat_id": "3",
            "bn": "201408-30",
            "enName": "Black Forest ",
            "simpleName": "\u9ed1\u68ee\u6797",
            "cakeGoodsId": "8",
            "weight": 1362
          },
          {
            "id": "251",
            "size": "30x30cm",
            "suite_amount": "\u9002\u540815-20\u4eba\u5206\u4eab",
            "booking_hour_limited": "24",
            "cutlery_content": "\u542b20\u5957\u9910\u5177\uff08\u8721\u70db\u9700\u5355\u72ec\u8ba2\u8d2d\uff09",
            "price": "958.00",
            "mktprice": "958.00",
            "spec": "5.0\u78c5",
            "pound": "5.00",
            "has_spec_img": 1,
            "img_url": "\/themes\/wap\/img\/5.00P-full-30.00.jpg",
            "is_default": "false",
            "has_stock": 9997,
            "cat_id": "3",
            "bn": "201408-50",
            "enName": "Black Forest ",
            "simpleName": "\u9ed1\u68ee\u6797",
            "cakeGoodsId": "8",
            "weight": 2270
          },
          {
            "id": "",
            "size": "",
            "suite_amount": "",
            "booking_hour_limited": "",
            "cutlery_content": "",
            "price": "",
            "has_spec_img": 1,
            "spec": "\u66f4\u591a",
            "pound": "more",
            "img_url": "\/themes\/wap\/img\/more.jpg",
            "is_default": "false",
            "has_stock": true
          }
        ],
        "saleTime": {
          "date": "\u4eca\u5929",
          "start_time": "20:30",
          "end_time": "21:30"
        },
        "catId": "3",
        "isCake": true,
        "goodsId": "8",
        "isSellOut": false,
        "imgUrl": "\/upload\/images\/65be5d2da873ef32df89bcf7c9c0b05e.jpg",
        "name": "\u5e38\u89c4\u6b3e"
      }, {
        "productsArr": [{
            "id": "18376",
            "size": "13x13cm",
            "suite_amount": "\u9002\u54083-4\u4eba\u5206\u4eab",
            "booking_hour_limited": "5",
            "cutlery_content": "\u542b5\u5957\u9910\u5177\uff08\u8721\u70db\u9700\u5355\u72ec\u8ba2\u8d2d\uff09",
            "price": "268.00",
            "mktprice": "268.00",
            "spec": "1.0\u78c5",
            "pound": "1.00",
            "has_spec_img": 1,
            "img_url": "\/themes\/wap\/img\/1.00P-full-13.00.jpg",
            "is_default": "true",
            "has_stock": 9994,
            "cat_id": "3",
            "bn": "20190424-30",
            "enName": "Black Forest ",
            "simpleName": "\u9ed1\u68ee\u6797(\u65e0\u9152\u6b3e)",
            "cakeGoodsId": "1068",
            "weight": 454
          },
          {
            "id": "18392",
            "size": "17x17cm",
            "suite_amount": "\u9002\u54087-8\u4eba\u5206\u4eab",
            "booking_hour_limited": "5",
            "cutlery_content": "\u542b10\u5957\u9910\u5177\uff08\u8721\u70db\u9700\u5355\u72ec\u8ba2\u8d2d\uff09",
            "price": "398.00",
            "mktprice": "398.00",
            "spec": "2.0\u78c5",
            "pound": "2.00",
            "has_spec_img": 1,
            "img_url": "\/themes\/wap\/img\/2.00P-full-17.00.jpg",
            "is_default": "false",
            "has_stock": 9999,
            "cat_id": "3",
            "bn": "20190424-50",
            "enName": "Black Forest ",
            "simpleName": "\u9ed1\u68ee\u6797(\u65e0\u9152\u6b3e)",
            "cakeGoodsId": "1068",
            "weight": 908
          },
          {
            "id": "18400",
            "size": "23x23cm",
            "suite_amount": "\u9002\u540811-12\u4eba\u5206\u4eab",
            "booking_hour_limited": "5",
            "cutlery_content": "\u542b15\u5957\u9910\u5177\uff08\u8721\u70db\u9700\u5355\u72ec\u8ba2\u8d2d\uff09",
            "price": "598.00",
            "mktprice": "598.00",
            "spec": "3.0\u78c5",
            "pound": "3.00",
            "has_spec_img": 1,
            "img_url": "\/themes\/wap\/img\/3.00P-full-23.00.jpg",
            "is_default": "false",
            "has_stock": 9999,
            "cat_id": "3",
            "bn": "20190424-60",
            "enName": "Black Forest ",
            "simpleName": "\u9ed1\u68ee\u6797(\u65e0\u9152\u6b3e)",
            "cakeGoodsId": "1068",
            "weight": 1362
          },
          {
            "id": "18408",
            "size": "30x30cm",
            "suite_amount": "\u9002\u540815-20\u4eba\u5206\u4eab",
            "booking_hour_limited": "24",
            "cutlery_content": "\u542b20\u5957\u9910\u5177\uff08\u8721\u70db\u9700\u5355\u72ec\u8ba2\u8d2d\uff09",
            "price": "958.00",
            "mktprice": "958.00",
            "spec": "5.0\u78c5",
            "pound": "5.00",
            "has_spec_img": 1,
            "img_url": "\/themes\/wap\/img\/5.00P-full-30.00.jpg",
            "is_default": "false",
            "has_stock": 9999,
            "cat_id": "3",
            "bn": "20190424-70",
            "enName": "Black Forest ",
            "simpleName": "\u9ed1\u68ee\u6797(\u65e0\u9152\u6b3e)",
            "cakeGoodsId": "1068",
            "weight": 2270
          },
          {
            "id": "",
            "size": "",
            "suite_amount": "",
            "booking_hour_limited": "",
            "cutlery_content": "",
            "price": "",
            "has_spec_img": 1,
            "spec": "\u66f4\u591a",
            "pound": "more",
            "img_url": "\/themes\/wap\/img\/more.jpg",
            "is_default": "false",
            "has_stock": true
          }
        ],
        "saleTime": {
          "date": "\u4eca\u5929",
          "start_time": "20:30",
          "end_time": "21:30"
        },
        "catId": "3",
        "isCake": true,
        "goodsId": "1068",
        "isSellOut": false,
        "imgUrl": "\/upload\/images\/65be5d2da873ef32df89bcf7c9c0b05e.jpg",
        "name": "\u65e0\u9152\u6b3e"
      }],
      "type": "multiply",
      "title": "\u53e3\u5473"
    }, // 商品种类详情数据
    tasteCurrent: 0, // 选中口味
    specCurrent: 0, // 选中规格
  },

  // 立即购买
  onBuy: function() {
    this.hidden();
    wx.showLoading({
      title: '跳转购物车中',
      success: function() {
        wx.hideLoading();
        wx.navigateTo({
          url: '/pages/cart/cart',
        })
      }
    })

  },

  // 加入购物车
  onAddCart: function() {
    this.hidden();
    wx.showToast({
      title: '加入成功',
      icon: "success"
    });
  },

  // 联系客服
  onContactService: function() {
    wx.showToast({
      title: '维护中',
      icon: "none"
    })
  },

  // 底部详情弹出模态框 规格点击选中
  onSpecActive: function(e) {
    this.setData({
      specCurrent: e.currentTarget.dataset.index
    });
  },
  // 底部详情弹出模态框 口味点击选中
  onTasteActive: function(e) {
    this.setData({
      tasteCurrent: e.currentTarget.dataset.index
    });
  },

  // 点击失效
  clickInvalid: function() {
    return false;
  },

  //移动按钮点击事件
  showModel: function(e) {
    moveY = 0;
    action = 'show';
    animationEvents(this, moveY, action);
  },
  //隐藏弹窗浮层
  hidden: function(e) {
    moveY = 200;
    action = 'hide';
    animationEvents(this, moveY, action);
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function(res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
      return {
        title: res.target.dataset.shareinfo.title,
        path: res.target.dataset.shareinfo.path,
        imageUrl: res.target.dataset.shareinfo.imageUrl
      }
    } else {
      return {
        title: '全新品种蛋糕，等你来尝哦！',
        path: 'pages/home/home',
        imageUrl: "http://59.110.237.148/tsy/static_file/applets_21cake/images/banner2.jpg"
      }
    }
  }
})

//动画事件 底部的弹出，背景层通过切换不同的class，添加一个transition的效果，使之有一个渐变的感觉。
function animationEvents(that, moveY, action) {
  that.animation = wx.createAnimation({
    transformOrigin: "50% 50%",
    duration: 400,
    timingFunction: "ease",
    delay: 0
  })
  that.animation.translateY(moveY + 'vh').step()
  if (action == 'show') {
    that.setData({
      animation: that.animation.export(),
      show: true,
      backgroundVisible: true,
      bg: 'bg',
      disableScroll: 'disableScroll'
    });
  } else if (action == 'hide') {
    that.setData({
      animation: that.animation.export(),
      show: false,
      backgroundVisible: false,
      bg: 'background',
      disableScroll: ''
    });
  }
}